# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: xguo

import itertools
import json
import sys

template = """
feed_subsystem_config:
  Spot.{exchange}:
    - BTC-USDT
    - {prod1}
    - {prod2}


sim_config:
  from_ts: 20190510
  to_ts: 20190530
  machine: feed-01.ap-northeast-1.aws
  result_file: {result_file}
"""

script = sys.argv[1]


def main():
  jobs_config = {'name': f'{script}_sim', 'working_dir': '/remote/iosg/home/xguo/slurm', 'jobs': []}
  jobs = jobs_config['jobs']

  bases = ['EOS', 'ETH', 'XRP', 'LTC']
  exchanges = ['Binance', 'Okex', 'Huobi']

  for base, exchange in itertools.product(bases, exchanges):
    prod1 = f'{base}-USDT'
    prod2 = f'{base}-BTC'
    result_file = f'/remote/iosg/home/xguo/trimm/result/{script}_{exchange}_{base}.json'
    config_content = template.format(prod1=prod1,
                                     prod2=prod2,
                                     exchange=exchange,
                                     result_file=result_file)
    config_file = f'/remote/iosg/home/xguo/trimm/{exchange}_{base}.yaml'
    with open(config_file, 'w') as out_file:
      out_file.write(config_content)
    command = f'source /remote/iosg/home/xguo/pyrunner/pyrunner.sh && ./pyrunner coin/experimental/xguo/fruit/grape/{script}_sim.py --config={config_file}'
    jobs.append({
        'name': f'{exchange}_{base}',
        'command': command,
    })
  print(json.dumps(jobs_config, indent=2))


if __name__ == '__main__':
  main()
